<?php
/**
 * @user:andy
 * @date:2021/6/16
 * @company:http://www.sjdphp.com
 * @desc:
 */

namespace app\common\server;


class Json
{
    const SUCCESS = 1;
    const NORMAL  = 0;
    const ERROR   = -1;


    /** 通用化错误返回格式
     * @param $code
     * @param string $msg
     * @param array $data
     * @param int $httpCode
     * @return \think\response\Json
     */
    public static function error($msg = '',$data = array(),$httpCode = 200){
        $result = array(
            'code' => self::ERROR,
            'msg'  => $msg,
            'data' => $data
        );

        return json($result,$httpCode);
    }

    /** 通用化成功返回格式
     * @param string $msg
     * @param $data
     * @param int $httpCode
     * @return \think\response\Json
     */
    public static function success($msg = '',$data = array(),$httpCode = 200){
        $result = array(
            'code' => self::SUCCESS,
            'msg'  => $msg,
            'data' => $data
        );

        return json($result,$httpCode);
    }

    /**
     * @param string $msg
     * @param array $data
     * @param int $httpCode
     * @return \think\response\Json
     */
    public static function normal($msg = '',$data = array(),$httpCode = 200){
        $result = array(
            'code' => self::NORMAL,
            'msg'  => $msg,
            'data' => $data
        );

        return json($result,$httpCode);
    }
}